package com.bamboo.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bamboo.model.SysMailSet;
import com.bamboo.service.SysMailSetService;
import com.bamboo.utils.PageUtils;
import com.bamboo.utils.Query;
import com.bamboo.utils.R;

/**
 * 发件邮箱账号设置
 *
 * @author zhanghai
 * @email walk_hai@163.com
 * @date 2017-04-07 12:16:29
 */
@RestController
@RequestMapping("sysmailset")
public class SysMailSetController {
    @Autowired
    private SysMailSetService sysMailSetService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sysmailset:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<SysMailSet> sysMailSetList = sysMailSetService.queryList(query);
        int total = sysMailSetService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(sysMailSetList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sysmailset:info")
    public R info(@PathVariable("id") Long id) {
        SysMailSet sysMailSet = sysMailSetService.queryObject(id);
        return R.ok().put("sysMailSet", sysMailSet);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sysmailset:save")
    public R save(@RequestBody SysMailSet sysMailSet) {
        sysMailSetService.save(sysMailSet);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sysmailset:update")
    public R update(@RequestBody SysMailSet sysMailSet) {
        sysMailSetService.update(sysMailSet);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sysmailset:delete")
    public R delete(@RequestBody Long[] ids) {
        sysMailSetService.deleteBatch(ids);
        return R.ok();
    }

}
